package com.neusoft.mapper;

import com.neusoft.po.Comment;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface CommentMapper {
    
    @Select("SELECT * FROM comment WHERE userId = #{userId} ORDER BY commentId DESC")
    public List<Comment> getCommentByUserId(@Param("userId") String userId);

    @Select("SELECT * FROM comment WHERE businessId = #{businessId} ORDER BY commentId DESC")
    public List<Comment> getCommentByBusinessId(@Param("businessId") Integer businessId);

    @Insert("INSERT INTO comment (userId, businessId, comment, `rank`) " +
        "VALUES (#{userId}, #{businessId}, #{comment}, #{rank})")
    @Options(useGeneratedKeys = true, keyProperty = "commentId", keyColumn = "commentId")
    Boolean createComment(Comment comment);

    @Update("UPDATE comment SET comment = #{comment}, `rank` = #{rank} WHERE commentId = #{commentId}")
    public Boolean updateComment(Comment comment);
}
